package tools;

import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;

public class WashDataNew {
    public static void main(String[] args) throws Exception {
        FileReader reader = new FileReader("/home/hdfs/chen/kylin2.4.0/cs_cube/data2/log0810.txt");
        BufferedReader br = new BufferedReader(reader);
        String line = null;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String rootDir = "/home/hdfs/chen/kylin2.4.0/cs_cube/data2/log/";
        BufferedWriter bw = null;
        HashMap<String, BufferedWriter> map = new HashMap<String, BufferedWriter>();
        while ((line=br.readLine())!=null){
            String[] ss = line.split("\\|");
            String date = sdf.format(new Date(Long.parseLong(ss[4])));
            String path = rootDir+date+"/log.txt";
            createFile(path);
            bw = map.get(path);
            if(bw==null){
                bw = new BufferedWriter(new FileWriter(path));
            }
            bw = new BufferedWriter(new FileWriter(path,true));
            bw.write(line+"\r\n");
            map.put(path,bw);
        }
        reader.close();
        for(BufferedWriter b:map.values()){
            b.close();
        }
    }

    public static void createFile(String file) throws IOException {
        File f = new File(file);
        if(!f.exists()){
            f.getParentFile().mkdirs();
            f.createNewFile();
        }
    }

}
